# -*- coding: utf-8 -*-
from django.contrib.auth.models import User
from django.contrib.auth.signals import user_logged_in, user_logged_out
from django.db import models
from sprt.admin.models import Dept
import time
#from django.db.models.signals import post_save


# Create your models here.
   

class UserDetail(models.Model):
#    auth_user_id=models.IntegerField(primary_key=True)
    user = models.OneToOneField(User)
#    photo_url = models.CharField(max_length=255, db_column="PHOTO_URL")
    GENDER_CHOICES=((1,u'男'),(0,u'女'))
    gender = models.SmallIntegerField(choices=GENDER_CHOICES,default=1)
    title = models.CharField(max_length=20,null=True, blank=True)
    birthday = models.DateField(null=True)
    schedule_list = models.IntegerField(default=0)
    superior_auth_user = models.ForeignKey(User,related_name='AUTH_USER_SUPERIOR_ID',null=True)
    dept = models.ForeignKey(Dept)
    
    
    class Meta:
        db_table='USER_DETAIL'
        
def create_user_detail(sender, instance, created, **kwargs):
    if created:
        UserDetail.objects.create(user=instance)
    
    #post_save.connect(create_user_detail, sender=User)
    
def update_checkin_log_login(sender, request, user, **kwargs):
    from sprt.checkin.models import update_first_login
    update_first_login(user)
    

def update_checkin_log_logout(sender, request, user, **kwargs):
    from sprt.checkin.models import update_last_logout
    update_last_logout(user)
    
user_logged_in.connect(update_checkin_log_login, sender=User)
user_logged_out.connect(update_checkin_log_logout, sender=User)

